package com.studykun.client.util;

import com.google.gwt.user.client.ui.DialogBox;
import com.studykun.client.model.AbstractAgent;
import com.studykun.client.model.Agent;
import com.studykun.client.model.World;
import com.studykun.client.ui.CardListDialog;

public class SystemAgent extends AbstractAgent {
  private World world_;
  
  public SystemAgent(
      final World world) {
    super(new SimpleAvatar("System", "system"));
    world_= world;
  }
  
  @Override
  public void onEcho(
      final EchoType echoType,
      final Room room,
      final Agent agent,
      final String message)
  {
    // Prevent infinite recursion cause by agent responding to itself.
    if (agent == this) {
      return;
    }
    
    switch (echoType) {
    case NORMAL:
      if (message.startsWith("/")) {
        if (message.equals("/help")) {
          room.echo(echoType, this, "Commands:");
          room.echo(echoType, this, "/about - Display information about Studykun.");
          room.echo(echoType, this, "/cheat - Display the answer.");
          room.echo(echoType, this, "/help - List commands.");
          room.echo(echoType, this, "/cards - Select cards to include in test.");
          room.echo(echoType, this, "/skip - Skip to next question.");
          room.echo(echoType, this, "/teachers - List teachers.");
        } else if (message.equals("/about")) {
          room.echo(echoType, this, "Studykun - Copyright © John Ky 2009.");
          room.echo(echoType, this, "Please do not redistribute without persmission.");
        } else if (message.equals("/cards")) {
          final DialogBox dialogBox = new CardListDialog(world_.getSyllabus());
          dialogBox.center();
          dialogBox.show();
        } else if (message.equals("/teachers")) {
          final TeachersPane teachersPane = new TeachersPane(world_);
          this.sayIn(room, teachersPane);
        }
      }
      break;
    }
  }
}
